##热图参数

##定义距离计算函数
p1 <- Heatmap(mat, name = "mat1", clustering_distance_rows = "pearson",
              column_title = "pre-defined distance method(1-pearson)")
p2 <- Heatmap(mat, name = "mat2", clustering_distance_rows = function(m) dist(m),
              column_title = "a function that calculates distance matrix")
p1 + p2
##聚类树颜色
library(dendextend)
row_dend = as.dendrogram(hclust(dist(mat)))
row_dend = color_branches(row_dend, k = 2) # `color_branches()` returns a dendrogram object
Heatmap(mat, name = "mat", cluster_rows = row_dend)
##row_dend_gp和column_dend_gp参数控制聚类树样式，使用此参数会覆盖row_dend和column_dend:
Heatmap(mat, name = "mat", cluster_rows = row_dend, row_dend_gp = gpar(col = "red"))
##从2.5.6版本以后，可以通过提供合适的nodePar给树的节点使用不同的形状
row_dend = dendrapply(row_dend, function(d) {
  attr(d, "nodePar") = list(cex = 0.8, pch = sample(20, 1), col = rand_color(1))
  return(d)
})
Heatmap(mat, name = "mat", cluster_rows = row_dend, row_dend_width = unit(2, "cm"))
##默认情况下，如果将cluster_rows/cluster_columns设置为逻辑值或聚类函数，聚类树会重新排序。 如果将cluster_rows/cluster_columns设置为聚类对象，则会关闭重排序。
m2 = matrix(1:100, nr = 10, byrow = TRUE)
Heatmap(m2, name = "mat1", row_dend_reorder = FALSE, column_title = "no reordering")
##分割行列，离散方法分割
Heatmap(mat, name = "mat", 
        row_split = rep(c("A", "B"), 9), column_split = rep(c("C", "D"), 12))
w